﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using BRMC.IntelligentCommunity.Configuration;
using BRMC.IntelligentCommunity.Web;

namespace BRMC.IntelligentCommunity.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class IntelligentCommunityDbContextFactory : IDesignTimeDbContextFactory<IntelligentCommunityDbContext>
    {
        public IntelligentCommunityDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<IntelligentCommunityDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true);

            IntelligentCommunityDbContextConfigurer.Configure(builder, configuration.GetConnectionString(IntelligentCommunityConsts.ConnectionStringName));

            return new IntelligentCommunityDbContext(builder.Options);
        }
    }
}